cmake_minimum_required(VERSION 4.0.0)

# Project
project(
    VashOS
    LANGUAGES C CXX ASM
)

# Variables
set(DIST_BINARY_DIR ${CMAKE_SOURCE_DIR}/dist)
set(UTILS_DIR ${CMAKE_SOURCE_DIR}/utils)

# C/C++
# Standard
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Compiler
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")

# Assembly
# Compiler
set(CMAKE_ASM_COMPILER "nasm")
set(CMAKE_ASM_FLAGS "-f bin")

# Targets

# Bootloader-s
# Bootloader
add_custom_target(
    VashOS-Bootloader
    COMMAND nasm -f bin ${CMAKE_SOURCE_DIR}/boot/boot.asm -o ${CMAKE_BINARY_DIR}/boot.bin
    DEPENDS ${CMAKE_SOURCE_DIR}/boot/boot.asm
    COMMENT "Building bootloader"
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

# Bootloader Only
add_custom_target(
    VashOS-Bootloader-Img
    COMMAND python.exe ${UTILS_DIR}/del.py ${DIST_BINARY_DIR}/boot.img
    COMMAND dd if="${CMAKE_BINARY_DIR}/boot.bin" of="${DIST_BINARY_DIR}/boot.img" bs=512
    DEPENDS VashOS-Bootloader
    COMMENT "Building bootloader img"
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
